/**
 * Filename:save.js
 * Used to define functions save or post information.
 * 
 * @author Nonsenser
 * mail:n0nsenser@hotmail.com
 */
var ajax_save = new Ajax();
if (ajax_save.hreq.overrideMimeType) 
{
	ajax_save.hreq.overrideMimeType("text/html");
}  
 
var data = new Array();
function PostComment(form)
{
	this.data = [];
	this.data['username'] = form.username.value;
	this.data['password'] = form.password.value;
	this.data['code']     = form.code.value;
	this.data['content']  = form.commcontent.value;
	this.data['logID']    = form.logID.value;
	this.data['action']   = form.action.value;
    var pairs = [];
    var regexp = /%20/g;

    for(var name in this.data) {
        var value = this.data[name].toString();
        var pair = encodeURIComponent(name).replace(regexp,"+") + '=' + encodeURIComponent(value).replace(regexp,"+");
        pairs.push(pair);
    }
	var postdata = pairs.join('&');
    ajax_save.post("./savecomm.php",postdata,Callback_PostComm,false);
}

function Callback_PostComm()
{
	if(ajax_save.hreq.readyState == 4)
	{
		if(ajax_save.hreq.status == 200)
		{
			var ret = ajax_save.hreq.responseText;
			if(ret.search(/successful/i) == -1){
				alert(ret);
			}
			else{
				alert("Comment posted successful\n");
				location.reload();
			}
		}else{
			alert("The page you requested is unavailable.");
		}
	}
}

function PostLogin(form)
{
	var LoginInfo = new Array();
	LoginInfo['username'] = form.username.value;
	LoginInfo['password'] = form.password.value;
	
	var pairs = [];
    var regexp = /%20/g;

    for(var name in LoginInfo) {
        var value = LoginInfo[name].toString();
        var pair = encodeURIComponent(name).replace(regexp,"+") + '=' + encodeURIComponent(value).replace(regexp,"+");
        pairs.push(pair);
    }
	var postdata = pairs.join('&');
	//alert(postdata);
    ajax_save.post("./checklogin.php",postdata,Callback_Login,false);
}

function Callback_Login()
{
	if(ajax_save.hreq.readyState == 4)
	{
		if(ajax_save.hreq.status == 200)
		{
			//alert(ajax_save.hreq.responseText);
			eval(ajax_save.hreq.responseText);
		}else{
		alert("The page you requested is unavailable.");
		}
	}
}

function GetFckContent()
{
	var oEditor = FCKeditorAPI.GetInstance('FCKeditor') ;
	var acontent=oEditor.GetXHTML();
	return acontent;
} 
